import app from "./instantiation";
import router from "./router";
import ElementPlus from "element-plus";
import zhCn from "element-plus/dist/locale/zh-cn.mjs";
import "./assets/fonts/fonts.css";
import "./assets/fonts/fontawesome.css";
import "./assets/scss/styles.scss";
import "./assets/scss/main.scss";
import "./assets/scss/element-variables.scss";
// import "./mock/index";

app
  .use(ElementPlus, {
    locale: zhCn,
  })
  .use(router)
  .mount("#app");

import { ElMessage } from "element-plus";
import { isLogin } from "./utils/index";
router.beforeEach((to, from, next) => {
  if (to.meta.hidden && !isLogin()) {
    ElMessage({
      message: "请先登录",
      type: "error",
    });
    setTimeout(() => {
      next({
        path: "/login",
      });
    }, 1000);
  } else {
    document.body.scrollTop = 0;
    document.documentElement.scrollTop = 0;
    window.pageYOffset = 0;
    if (to.meta.title) {
      document.title = to.meta.title;
    }
    next();
  }
});
